home *** CD-ROM | disk | FTP | other *** search
- //: C14:Compose.cpp
- // From Thinking in C++, 2nd Edition
- // Available at http://www.BruceEckel.com
- // (c) Bruce Eckel 1999
- // Copyright notice in Copyright.txt
- // Reuse code with composition
- #include "Useful.h"
-
- class Y {
- int i;
- public:
- X x; // Embedded object
- Y() { i = 0; }
- void f(int ii) { i = ii; }
- int g() const { return i; }
- };
-
- int main() {
- Y y;
- y.f(47);
- y.x.set(37); // Access the embedded object
- } ///:~
-